<template>
  <div>
    <p class="title">新建用户</p>
    <div class="all">
      <div class="left">
        <el-form ref="form" :model="form" label-width="100px">
          <el-form-item label="手机号：">
            <el-input v-model="form.phone" class="phone"></el-input>
          </el-form-item>
          <el-form-item label="密码：">
            <el-input v-model="form.password" class="phone"></el-input>
          </el-form-item>
          <el-form-item label="用户昵称：">
            <el-input v-model="form.username" class="phone"></el-input>
          </el-form-item>

          <el-form-item label="兴趣标签：">
            <el-checkbox-group v-model="form.type">
              <el-checkbox
                v-for="item in form.interestType"
                :key="item.id"
                :label="item.name"
                name="type"
              ></el-checkbox>
            </el-checkbox-group>
          </el-form-item>
          <el-form-item label="所在地：">
            <Cityarea />
          </el-form-item>
          <el-form-item label="性别：">
            <el-radio-group v-model="form.sex">
              <el-radio label="男"></el-radio>
              <el-radio label="女"></el-radio>
            </el-radio-group>
          </el-form-item>

          <el-form-item label="是否认证：">
            <el-radio-group v-model="form.aut">
              <el-radio label="是"></el-radio>
              <el-radio label="否"></el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="是否会员：">
            <el-radio-group v-model="form.vip">
              <el-radio label="是"></el-radio>
              <el-radio label="否"></el-radio>
            </el-radio-group>
          </el-form-item>

          <el-form-item label="出生日期：">
            <el-col :span="11">
              <el-date-picker
                type="date"
                placeholder="选择日期"
                v-model="form.date1"
                style="width: 100%"
              ></el-date-picker>
            </el-col>
          </el-form-item>

          <el-form-item label="个性签名：">
            <el-input
              type="textarea"
              v-model="form.desc"
              placeholder="请输入签名"
              class="desc"
            ></el-input>
          </el-form-item>
          <el-form-item>
            <el-button>取消</el-button>
            <el-button type="primary" @click="onSubmit">保存</el-button>
          </el-form-item>
        </el-form>
      </div>
      <div class="right">
        <div class="tx">
          <el-upload
            class="avatar-uploader"
            action="https://jsonplaceholder.typicode.com/posts/"
            :show-file-list="false"
            :on-success="handleAvatarSuccess"
            :before-upload="beforeAvatarUpload"
          >
            <img v-if="imageUrl" :src="imageUrl" class="avatar" />
            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
          </el-upload>
           <el-button type="primary" class="uptx">上传头像</el-button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import Cityarea from "../../components/area.vue";
export default {
  components: {
    Cityarea,
  },
  data() {
    return {
      imageUrl: "",
      form: {
        phone: "",
        password: "",
        username: "",
        region: "",
        date1: "",
        type: [],
        sex: "",
        aut: "",
        vip: "",

        desc: "",
        interestType: [
          { id: 1, name: "摄影" },
          { id: 2, name: "旅游" },
          { id: 3, name: "美食" },
          { id: 4, name: "运动" },
          { id: 5, name: "历史" },
          { id: 6, name: "模特" },
          { id: 7, name: "歌唱" },
          { id: 8, name: "戏曲" },
          { id: 9, name: "舞蹈" },
          { id: 10, name: "音乐" },
          { id: 11, name: "生活" },
          { id: 12, name: "宠物" },
          { id: 13, name: "养生" },
          { id: 14, name: "书画" },
          { id: 15, name: "健康" },
          { id: 16, name: "其他" },
          { id: 17, name: "亲子" },
          { id: 18, name: "家庭" },
          { id: 19, name: "娱乐" },
        ],
      },
    };
  },
  methods: {
    handleAvatarSuccess(res, file) {
      this.imageUrl = URL.createObjectURL(file.raw);
    },
    beforeAvatarUpload(file) {
      const isJPG = file.type === "image/jpeg";
      const isLt2M = file.size / 1024 / 1024 < 2;

      if (!isJPG) {
        this.$message.error("上传头像图片只能是 JPG 格式!");
      }
      if (!isLt2M) {
        this.$message.error("上传头像图片大小不能超过 2MB!");
      }
      return isJPG && isLt2M;
    },
    onSubmit() {
      console.log("submit!");
    },
  },
};
</script>

<style lang="scss" scoped>
.title {
  margin-top: -10px;
}
.left {
  width: 70%;
}
.right {
  width: 30%;
}
.phone {
  width: 200px;
}
.el-checkbox-group {
  width: 410px;
}
.el-button {
  width: 150px;
  margin-left: 40px;
}
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}
.avatar {
  width: 178px;
  height: 178px;
  display: block;
}
.all {
  display: flex;
  justify-content: space-between;
}
.tx{
  width: 178px;
  height: 178px;
  border: 1px solid #ccc;
  border-radius: 50%;
}
.avatar{
  border-radius: 50%;
}
.uptx{
  width: 178px;
  margin: 50px 0 0 0;

}
</style>